package veilingsite.servlets.nl;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class BaseServlet
 */
public class MainServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MainServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		RequestDispatcher view = null;
		view = request.getRequestDispatcher("VeilingServlet?recenteVeilingen");
		
		// redirect to main
		if (request.getQueryString() != null) {
			String[] url = request.getQueryString().split("=");
			
			if (url[0].equals("page") && url[1].equals("login")) {
				view = request.getRequestDispatcher("/WEB-INF/login.jsp");
			} else if (url[0].equals("page") && url[1].equals("newUser")){
				view = request.getRequestDispatcher("/WEB-INF/newUser.jsp");
			} else if (url[0].equals("page") && url[1].equals("mijnBiedingen")) {
				view = request.getRequestDispatcher("/WEB-INF/mijnBiedingen.jsp");
			} else if (url[0].equals("page") && url[1].equals("mijnVeilingen")) {
				view = request.getRequestDispatcher("/WEB-INF/mijnVeilingen.jsp");
			} else if (url[0].equals("page") && url[1].equals("newVeiling")) {
				view = request.getRequestDispatcher("/WEB-INF/newVeiling.jsp");
			} else if (url[0].equals("page") && url[1].equals("recenteVeilingen")) {
				view = request.getRequestDispatcher("VeilingServlet?recenteVeilingen");
			}
		}
		view.forward(request, response);
		
	}
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
